package network

import (
	"io/ioutil"
	"net/http"
	"strings"
)

/**
发起get请求
*/
func HttpGet(url string) string {
	resp, err := http.Get(url)
	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	return string(body)
}

func HttpPost(url string) string {
	resp, err := http.Post(url,
		"application/x-www-form-urlencoded",
		strings.NewReader("name=cjb&age=24"))
	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	return string(body)
}

